using System.Windows.Forms;
using System.Xml.Serialization;
using Lizk.SimpleHUD;

namespace SharpMedia.Input
{
    [XmlInclude(typeof(KeyboardCommand))]
    [XmlInclude(typeof(MouseCommand))]
    [XmlInclude(typeof(MouseWheelCommand))]
    public abstract class InputCommand
    {
        protected HUDCommands command;
        public abstract int Key
        {
            get;
        }

        public virtual HUDCommands Command
        {
            get { return command; }
            set { command = value; }
        }

    }
    
    
    public class KeyboardCommand : InputCommand
    {
        private Keys key;

        public KeyboardCommand()
        {
        }

        public KeyboardCommand(Keys key, Keys modifiers, HUDCommands command)
        {
            this.key = key;
            this.command = command;
            this.modifiers = modifiers;
        }

        public Keys KeyboardKey
        {
            get { return key; }
            set { key = value; }
        }

        private Keys modifiers;

        [XmlAttribute("modifiers")]
        public Keys Modifiers
        {
            get { return modifiers; }
            set { modifiers = value; }
        }


        public override int Key
        {
            get { return (int)key; }
        }

        public override string ToString()
        {
            string mods = "";

            if ((modifiers & Keys.Control) == Keys.Control)
            {
                mods = "Ctrl+";
            }

            if ((modifiers & Keys.Shift) == Keys.Shift)
            {
                mods += "Shift+";
            }

            if ((modifiers & Keys.Alt) == Keys.Alt)
            {
                mods += "Alt+";
            }

            return mods+KeyboardKey.ToString();
        }

    }

    public class MouseCommand : InputCommand
    {
        private MouseButtons button;
        public MouseCommand(){}

        public MouseButtons Button
        {
            get { return button; }
            set { button = value; }
        }



        public MouseCommand(MouseButtons button, HUDCommands command)
        {
            this.button = button;
            this.command = command;
        }

        public override int Key
        {
            get { return (int)button; }
        }

        public override string ToString()
        {
            return Button.ToString();
        }

    }
    public class MouseWheelCommand : InputCommand
    {
        private bool up;
        public MouseWheelCommand() { }

        public bool Up
        {
            get { return up; }
            set { up = value; }
        }



        public MouseWheelCommand(bool up, HUDCommands command)
        {
            this.up = up;
            this.command = command;
        }

        public override int Key
        {
            get { return up ? 1 : 0; }
        }
    }
}
